<?php
include $this->Render('header.php');
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASE_STYLE;?>/css/admin.css" />
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/dyhl.linkpage.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/common.js"></script>
<style type="text/css">
.tongrong-box {
	padding-left:30px;
	padding-right:30px;
}
</style>
<div class="tongrong-box" style="width:556px;">
	<form class="login-box-form J-ajaxForm" action="<?php echo $this->id > 0 ? '/region/update/option/save/' : '/region/save/option/save/';?>" method="post" autocomplete="off">
	<div class="tongrong-box-main">
    	<table width="100%" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="90px" height="35">大区编号：</td>
                <td>
                	<input name="rg_code" type="text" id="rg_code" size="35" value="<?php echo $this->data['rg_code'];?>" />
                </td>
            </tr>
            <tr>
            	<td height="35">大区名称：</td>
                <td>
                	<input name="rg_name" type="text" id="rg_name" size="35" value="<?php echo $this->data['rg_name'];?>" />
                </td>
            </tr>
            <tr>
            	<td height="35">所在地省市：</td>
                <td id="areas">
                	<select id="province" name="rg_province" class="mr15" ></select>
                    <select id="city" name="rg_city"></select>
                    <input id="test" type="text" style="visibility:hidden;width:0;" value="" alt="请选择完整地区信息！"><label></label>
                </td>
            </tr>
        </table>
    </div>
    <div class="luru-box-btn mt50"  style="margin-right:100px;">
		<input type="hidden" name="option" value="save" />
		<input type="hidden" name="id" value="<?php echo $this->id;?>" />
    	<input class="btn-submit-blue fn-left mr15 J-submit" type="submit" value="提交" />
        <a class="a-btn-close J-a-btn-close" href="javascript:;">关闭</a>
    </div>
	</form>
</div>

<script>
	$("#areas").Linkage({ url:"/public/ajax/?option=city",selected:['<?php echo empty($this->data['rg_province']) ? '浙江省' : $this->data['rg_province'];?>','<?php echo empty($this->data['rg_city']) ? '杭州市' : $this->data['rg_city'];?>',''],callback:function(data){
		var text = new Array();
		var value = new Array();
		for(i in data[0]){
		  if(data[0][i]!=0){
			text.push(data[1][i]);
			value.push(data[0][i]);
		  }
		}
		$("#test").val(value.join(','));
		FireEvent(document.getElementById("test"),"change");
	}});
	
	//关闭弹出
	$(".J-a-btn-close").on('click',function(){
		var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
		parent.Ext.getCmp(winElement.id).close();
	});
	
	$(document).ready(function(e) {
        $(".J-submit").on('click',function(){
			$(this).dyhlForm({
				beforefunction:submitChk,
				nofunction:function(){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask(); 
				},
				sucessfunction:function(data){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask(); 
					if(data['success']){
						Ext.Msg.alert('提示','提交成功',function(){
							window.parent.App.store.reload();
							var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
							parent.Ext.getCmp(winElement.id).close();
						});
					}else{
						Ext.Msg.alert('提示',data['msg']);
					}
				}	
			});	
		});
    });
	
	//表单验证
	function submitChk(){
		if($("#rg_code").val() == ''){
			Ext.Msg.alert('提示','大区编号不能为空!');	
			return false;
		}
		
		if($("#rg_name").val() == ''){
			Ext.Msg.alert('提示','大区名称不能为空!');	
			return false;
		}
		
		$(".J-submit").prop('disabled',true);
		Ext.getBody().mask("数据提交中，请稍等");
			
	}
	
</script>

<?php include $this->Render('footer.php'); ?>